package com.example.springboot.controller;


import com.example.springboot.pojo.Dishinfo;
import com.example.springboot.pojo.Result;
import com.example.springboot.service.DishinfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//controller层接受请求，响应数据
@Slf4j
@RestController
public class DishinfoController {
    @Autowired
    private DishinfoService dishinfoService;
    @GetMapping("/emps")
    public Result list(){
        log.info("查询表的所有数据");
        List<Dishinfo> dishinfoList = dishinfoService.list();
        return Result.success(dishinfoList);

    }
    @DeleteMapping ("/emps/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("根据id删除用户信息:{}",ids);
        dishinfoService.delete(ids);
        return Result.success();

    }

    @GetMapping ("/emps/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据id查询用户信息:{}",id);
        Dishinfo dishinfo = dishinfoService.selectById(id);
        return Result.success(dishinfo);

    }
    //  @RequestBody --封装json格式的对象
    @PostMapping("/emps")
    public Result add(@RequestBody Dishinfo dishinfo){
        log.info("增加用户信息:{}",dishinfo);
        dishinfoService.add(dishinfo);
        return Result.success();

    }
    @PutMapping ("/emps")
    public Result update(@RequestBody Dishinfo dishinfo) {

        log.info("根据id修改用户信息:{}",dishinfo);
        dishinfoService.update(dishinfo);
        return Result.success(dishinfo);
    }
}
